package com.sun.test.config;

import com.sun.test.task.QuartzTask;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @author zhangquanwei
 * @version 1.0
 * @date 2024-12-18 17:37
 */
@Configuration
public class QuartzTaskConfig {

    @Bean
    public JobDetail simpleJobDetail(){
        return JobBuilder.newJob(QuartzTask.class)
                .withIdentity("quartzTaskJob")
                .storeDurably(true)
                .build();
    }

    @Bean
    public Trigger simpleJobTrigger() {
        SimpleScheduleBuilder simpleScheduleBuilder = SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever();
        return TriggerBuilder.newTrigger().forJob(simpleJobDetail()).withIdentity("quartzTaskJobTrigger").withSchedule(simpleScheduleBuilder).build();
    }
}
